<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('留言板列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>标题：</label>
                                <input type="text" name="mbTopic"/>
                            </li>
                            <li>
                                <label>留言类型：</label>
                                <select name="mbType" th:with="type=${@dict.getType('mbs_message_board_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>处理状态：</label>
                                <select name="disposeStatus" th:with="type=${@dict.getType('mbs_dispose_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>处理等级：</label>
                                <select name="disposeLevel" th:with="type=${@dict.getType('mbs_dispose_level')}">
                                    <option value="">所有</option>
                                    <option value="-1">未分配</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>业务员：</label>
                                <select name="disposer">
                                    <option value="">所有</option>
                                    <option value="-1">未分配</option>
                                    <option th:each="user : ${disposer}" th:text="${user.userName}" th:value="${user.userId}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-info multiple disabled" onclick="javascript:levelDispose()" shiro:hasPermission="mbs:dispose:distribute:level">
                    <i class="fa fa-edit"></i> 等级分配
                </a>
                <a class="btn btn-info multiple disabled" onclick="javascript:verifierDispose()" shiro:hasPermission="mbs:dispose:distribute:verifier">
                    <i class="fa fa-edit"></i> 业务员分配
                </a>
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="mbs:mbinfo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="mbs:mbinfo:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="mbs:mbinfo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="mbs:mbinfo:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('mbs:mbinfo:detail')}]];
        var editFlag = [[${@permission.hasPermi('mbs:mbinfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('mbs:mbinfo:remove')}]];
        var disposeFlag = [[${@permission.hasPermi('mbs:dispose:status')}]];
        var disposeContentFlag = [[${@permission.hasPermi('mbs:dispose:content:status')}]];
        var mbTypeDatas = [[${@dict.getType('mbs_message_board_type')}]];
        var dLevelDatas = [[${@dict.getType('mbs_dispose_level')}]];
        var dStatusDatas = [[${@dict.getType('mbs_dispose_status')}]];
        var prefix = ctx + "mbs/mbinfo";
        var disposePrefix = ctx + "mbs/dispose";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "留言板",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'mbId',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'mbTopic',
                    title: '标题'
                },
                {
                    field: 'mbContent',
                    title: '内容',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    field: 'mbType',
                    title: '留言类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(mbTypeDatas, value);
                    }
                },
                {
                    field: 'disposeStatus',
                    title: '处理状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(dStatusDatas, value);
                    }
                },
                {
                    field: 'disposeLevel',
                    title: '处理等级',
                    formatter: function(value, row, index) {
                        if(value === '' || value === null){
                            return '<span style="color: red">未分配等级</span>';
                        }
                       return $.table.selectDictLabel(dLevelDatas, value);
                    }
                },
                {
                    field: 'disposer',
                    title: '业务员',
                    formatter: function(value, row, index) {
                        if(value === '' || value === null){
                            return '<span style="color: red">未分配</span>';
                        }else{
                            return value;
                        }
                    }
                },
                    {
                        field: 'disposeContent',
                        title: '回复',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.table.tooltip(value, 10, "open");
                        }
                    },
                {
                    field: 'createTime',
                    title: '提交时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.mbId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.mbId + '\')"><i class="fa fa-search"></i>详细</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + disposeContentFlag + '" href="javascript:void(0)" onclick="disposeContent(\'' + row.mbId + '\')"><i class="fa fa-adjust"></i>回复</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + disposeFlag + '" href="javascript:void(0)" onclick="dispose(\'' + row.mbId + '\')"><i class="fa fa-check"></i>已处理</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.mbId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function levelDispose(){
            var rows = $.table.selectColumns("mbId");
            if (rows.length == 0) {
                $.modal.alertWarning("请选择数据!");
                return;
            }
            var mbIds = "";
            for (var i = 0; i < rows.length; i++) {
                if(i != rows.length - 1){
                    mbIds += rows[i] + ",";
                }else{
                    mbIds += rows[i];
                }
            }
            $.modal.open("分配等级",disposePrefix + "/distribute/level?mbIds="+mbIds,300,210);
        }

        function verifierDispose(){
            var rows = $.table.selectColumns("mbId");
            if (rows.length == 0) {
                $.modal.alertWarning("请选择数据!");
                return;
            }
            var mbIds = "";
            for (var i = 0; i < rows.length; i++) {
                if(i != rows.length - 1){
                    mbIds += rows[i] + ",";
                }else{
                    mbIds += rows[i];
                }
            }
            $.modal.open("分配业务员",disposePrefix + "/distribute/verifier?mbIds="+mbIds,300,210);
        }

        function dispose(mbId) {
            var url = disposePrefix + "/status";
            var data = {"mbId": mbId ,"disposeStatus": 1 };
            console.log(data);
            $.operate.post(url, data);
        }


        function disposeContent(mbId) {
            var url = disposePrefix + "/reply?mbId=" + mbId;
            $.modal.open("回复",url,300,300);
        }
    </script>
</body>
</html>